﻿//********************************************************************************//
//创建日期：<创建日期，2016-10-19>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：退回灌费
//********************************************************************************//
using BLL;
using BLL.Access;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;

namespace Web.Pages.QuShui.DiXiaS.ZhangWuGL
{
    public partial class TuiHuiGF : BasePage
    {

        #region 属性
        private DataTable dtGrid
        {
            get
            {
                return ViewState["dtGrid"] as DataTable;
            }
            set
            {
                ViewState["dtGrid"] = value;
            }
        }

        /// <summary>
        /// 内部转账信息id
        /// </summary>
        private int HGF_ID
        {
            get
            {
                return Convert.ToInt32(ViewState["HGF_ID"]);
            }
            set
            {
                ViewState["HGF_ID"] = value;
            }
        }

        #endregion

        #region 变量
        /// <summary>
        /// 内部转账信息BLL
        /// </summary>
        YS_ZW_NEIBUZZXXBLL _YS_ZW_NEIBUZZXXBLL = new YS_ZW_NEIBUZZXXBLL();
        /// <summary>
        /// 用户信息BLL
        /// </summary>
        YS_YG_YONGHUXXBLL _YS_YG_YONGHUXXBLL = new YS_YG_YONGHUXXBLL();
        /// <summary>
        /// 账务信息BLL
        /// </summary>
        YS_ZW_YINGYEZBLL _YS_ZW_YINGYEZBLL = new YS_ZW_YINGYEZBLL();
        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _spHelper = new SpHelper();
        /// <summary>
        /// 日志操作类
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();
        #endregion

        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }

            this.dtGrid = _YS_ZW_NEIBUZZXXBLL.SelectYS_ZW_NEIBUZZXXesDynamic("i_jlzt=0 and nvl(s_by1,0)=0", "d_chulirq desc");
            this.gvGrid.DataSource = this.dtGrid;
            this.gvGrid.DataBind();

        }

        /// <summary>
        /// 取消内部转账
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuXiaoNBZZ_Click(object sender, EventArgs e)
        {
            DataRow[] dr = this.dtGrid.Select("ID=" + this.HGF_ID);
            int bh_out = Convert.ToInt32(dr[0].ItemArray[4]);
            int bh_in = Convert.ToInt32(dr[0].ItemArray[5]);
            int clr = Convert.ToInt32(dr[0].ItemArray[3]);
            decimal je = Convert.ToInt32(dr[0].ItemArray[6]);
            int? result = -1;
            _spHelper.P_YS_ZW_NEIBUZZ(bh_out, bh_in, "", clr, je, this.HGF_ID, out result);
            if (result == 1)
            {
                InitData();
            }
        }

        /// <summary>
        /// 确认转账
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQueDing_Click(object sender, EventArgs e)
        {
            
        }

        /// <summary>
        /// 转账信息列表，行改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvGrid_FocusedRowChanged(object sender, EventArgs e)
        {
            if (this.dtGrid != null && this.dtGrid.Rows.Count > 0)
            {
                this.HGF_ID = Convert.ToInt32(this.gvGrid.GetRowValues(this.gvGrid.FocusedRowIndex, "ID"));
                SetDataTab1();
            }
        }

        /// <summary>
        /// 前台表格行改变事件回调方法
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            int result = -1;
            string msg = "";

            string yhh = this.hdCollection.Get("yhh").ToString();
            int ym = Convert.ToInt32(this.hdCollection.Get("ym"));
            if (e.Parameter == "setinfo_out")
            {
                //先验证是否有加价开账记录
                DataTable dt_out = _YS_ZW_YINGYEZBLL.SelectYS_ZW_YINGYEZsDynamic(string.Format("S_YONGHUH='{0}' AND I_Y*100+I_M={1}", yhh, ym), null);
                //验证通过后，将该用户号对应的消息显示在输入框内
                if (dt_out != null && dt_out.Rows.Count > 0)
                {
                    result = 1;
                }
                if (result == 1)
                {
                    decimal ysje_out = Convert.ToDecimal(dt_out.Rows[0]["N_YINGSHOUJE"]);
                    decimal ssje_out = Convert.ToDecimal(dt_out.Rows[0]["N_SHISHOUJE"]);
                    int bh_out = Convert.ToInt32(dt_out.Rows[0]["I_FEIYONGBH"]);
                    DataTable dt = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format("S_YONGHUH='{0}'", yhh), null);
                    string yhm_out = dt != null && dt.Rows.Count > 0 ? dt.Rows[0]["S_YONGHUM"].ToString() : "";
                    int r_out = 1;
                    msg = string.Join("|", Convert.ToString(result), Convert.ToString(yhm_out), Convert.ToString(ysje_out), Convert.ToString(ssje_out), Convert.ToString(r_out), Convert.ToString(bh_out));
                }
                else
                {
                    msg = string.Join("|", Convert.ToString(result));
                }

            }
            else if (e.Parameter == "setinfo_in")
            {
                //先验证是否有加价开账记录 
                DataTable dt_in = _YS_ZW_YINGYEZBLL.SelectYS_ZW_YINGYEZsDynamic(string.Format("S_YONGHUH='{0}' AND I_Y*100+I_M={1}", yhh, ym), null);
                //验证通过后，将该用户号对应的消息显示在输入框内
                if (dt_in != null && dt_in.Rows.Count > 0)
                {
                    result = 1;
                }
                if (result == 1)
                {
                    decimal ysje_in = Convert.ToDecimal(dt_in.Rows[0]["N_YINGSHOUJE"]);
                    decimal ssje_in = Convert.ToDecimal(dt_in.Rows[0]["N_SHISHOUJE"]);
                    DataTable dt = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format("S_YONGHUH='{0}'", yhh), null);
                    int bh_in = Convert.ToInt32(dt_in.Rows[0]["I_FEIYONGBH"]);
                    string yhm_in = dt != null && dt.Rows.Count > 0 ? dt.Rows[0]["S_YONGHUM"].ToString() : "";
                    //txtYongHuM_in2.Text = yhm_in;
                    //txtYingShouJE_in2.Text = ysje_in.ToString();
                    //txtShiShouJE_in2.Text = ssje_in.ToString();
                    int r_in = 1;
                    msg = string.Join("|", Convert.ToString(result), Convert.ToString(yhm_in), Convert.ToString(ysje_in), Convert.ToString(ssje_in), Convert.ToString(r_in), Convert.ToString(bh_in));
                }
                else
                {
                    msg = string.Join("|", Convert.ToString(result));
                }

            }
            else if (e.Parameter == "qdzz")
            {
               
            }

            else if (e.Parameter == "qxnbzz")
            {
                DataRow[] dr = this.dtGrid.Select("ID=" + yhh);
                int bh_out = Convert.ToInt32(dr[0].ItemArray[4]);
                int bh_in = Convert.ToInt32(dr[0].ItemArray[5]);
                int clr = Convert.ToInt32(dr[0].ItemArray[3]);
                decimal je = Convert.ToInt32(dr[0].ItemArray[6]);
                int? result2 = -1;
                _spHelper.P_YS_ZW_NEIBUZZ(bh_out, bh_in, "", clr, je, this.HGF_ID, out result2);
                msg = string.Join("|", Convert.ToString(result2));
            }
            e.Result = e.Parameter + "|0|" + msg;
        }

        protected void gvGrid_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
        {
            InitData();
        }

        #endregion

        #region 方法

        /// <summary>
        /// 页面加载
        /// </summary>
        private void InitData()
        {
            int wtype = BusinessTool.WType;
            //加载列表信息
            //this.dtGrid = null;// _YS_ZW_NEIBUZZXXBLL.SelectYS_ZW_NEIBUZZXXesDynamic("i_jlzt=0 and nvl(s_by1,0)=0", "d_chulirq desc");
            //this.gvGrid.DataSource = this.dtGrid;
            //this.gvGrid.DataBind();
            //if (this.dtGrid != null && this.dtGrid.Rows.Count > 0)
            //{
            //    this.gvGrid.FocusedRowIndex = 0;
            //    //SetDataTab1();
            //}
            deKaiZhangRQ.Text = DateTime.Now.ToString("yyyy-MM-dd");
            txtZWNY.Text = BusinessTool.GetSLYMorZWNY(1, wtype).ToString();
        }

        /// <summary>
        /// 加载列表下方输入框信息
        /// </summary>
        private void SetDataTab1()
        {
           
        }

        /// <summary>
        /// 验证是否输入框都显示不为空
        /// </summary>
        /// <returns></returns>
        private bool Validate()
        {
            bool res = true;
           

            return res;
        }


        #endregion


    }
}